package com.firefly.admin.config.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.firefly.admin.common.annotations.annotation.OperationLog;
import com.firefly.admin.common.enums.OperationModuleEnum;
import com.firefly.admin.common.enums.OperationTypeEnum;
import com.firefly.admin.common.vo.Result;
import com.firefly.admin.config.entity.FySystemDictionary;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import com.firefly.admin.config.service.FySystemDictionaryService;
import com.firefly.admin.config.vo.SystemDictionaryQueryVo;
import com.firefly.admin.config.vo.SystemDictionaryStatusUpdateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api(tags = "系统字典接口API")
@RestController
@RequestMapping("/system/dictionary")
public class FySystemDictionaryController {
    @Autowired
    private FySystemDictionaryService fySystemDictionaryService;

    /**
     * 分页查询系统字典接口
     *
     * @param systemDictionaryQueryVo 分页查询参数
     * @return 分页列表
     */
    @ApiOperation(value = "分页查询系统字典接口", notes = "分页查询系统字典接口", httpMethod = "GET")
    @PreAuthorize(value = "hasAuthority('system:dictionary')")
    @GetMapping("/list")
    public Result<Page<FySystemDictionary>> getSystemDictionaryList(SystemDictionaryQueryVo systemDictionaryQueryVo) {
        return fySystemDictionaryService.getSystemDictionaryList(systemDictionaryQueryVo);
    }

    /**
     * 获取系统字典信息接口
     *
     * @param dictionaryId 字典ID
     * @return 字典信息
     */
    @ApiOperation(value = "获取系统字典信息接口", notes = "通过字典ID获取字典详细信息", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictionaryId", value = "字典ID", required = true, paramType = "path", dataType = "Long")
    })
    @GetMapping("/{dictionaryId}")
    public Result<FySystemDictionary> getSystemDictionary(@PathVariable Long dictionaryId) {
        return fySystemDictionaryService.getSystemDictionary(dictionaryId);
    }

    /**
     * 系统字典信息新增接口
     *
     * @param fySystemDictionary 字典信息
     * @return 操作结果
     */
    @ApiOperation(value = "系统字典信息新增接口", notes = "系统字典信息新增接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.CONFIG_MANAGE, operateType = OperationTypeEnum.SYSTEM_DICTIONARY, operateDesc = "系统字典新增")
    @PreAuthorize(value = "hasAuthority('system:dictionary:add')")
    @PostMapping("/add")
    public Result<FySystemDictionary> add(@RequestBody FySystemDictionary fySystemDictionary) {
        return fySystemDictionaryService.add(fySystemDictionary);
    }

    /**
     * 系统字典信息编辑接口
     *
     * @param fySystemDictionary 字典信息
     * @return 操作结果
     */
    @ApiOperation(value = "系统字典信息编辑接口", notes = "系统字典信息编辑接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.CONFIG_MANAGE, operateType = OperationTypeEnum.SYSTEM_DICTIONARY, operateDesc = "系统字典编辑")
    @PreAuthorize(value = "hasAuthority('system:dictionary:update')")
    @PostMapping("/update")
    public Result<FySystemDictionary> update(@RequestBody FySystemDictionary fySystemDictionary) {
        return fySystemDictionaryService.update(fySystemDictionary);
    }

    /**
     * 系统字典状态编辑接口
     *
     * @param systemDictionaryStatusUpdateVo 状态信息
     * @return 操作结果
     */
    @ApiOperation(value = "系统字典状态编辑接口", notes = "系统字典状态编辑接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.CONFIG_MANAGE, operateType = OperationTypeEnum.SYSTEM_DICTIONARY, operateDesc = "系统字典修改状态")
    @PreAuthorize(value = "hasAuthority('system:dictionary:update:status')")
    @PostMapping("/update/status")
    public Result<FySystemDictionary> updateStatus(@RequestBody SystemDictionaryStatusUpdateVo systemDictionaryStatusUpdateVo) {
        return fySystemDictionaryService.updateStatus(systemDictionaryStatusUpdateVo);
    }

    /**
     * 系统字典信息删除接口
     *
     * @param dictionaryId 字典ID
     * @return 操作结果
     */
    @ApiOperation(value = "系统字典信息删除接口", notes = "系统字典信息删除接口", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictionaryId", required = true, value = "字典ID", paramType = "query", dataType = "Long")
    })
    @OperationLog(module = OperationModuleEnum.CONFIG_MANAGE, operateType = OperationTypeEnum.SYSTEM_DICTIONARY, operateDesc = "系统字典删除")
    @PreAuthorize(value = "hasAuthority('system:dictionary:delete')")
    @PostMapping("/delete")
    public Result<String> delete(Long dictionaryId) {
        return fySystemDictionaryService.delete(dictionaryId);
    }

    /**
     * 系统字典编码校验接口
     *
     * @param dictionaryCode 字典编码
     * @param dictionaryId   字典ID
     * @return 校验结果
     */
    @ApiOperation(value = "系统菜单编码校验接口", notes = "系统菜单编码校验接口", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictionaryId", required = true, value = "字典ID", paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "dictionaryCode", required = true, value = "字典编码", paramType = "query", dataType = "String")
    })
    @GetMapping("/code/check")
    public Result<String> dictionaryCodeCheck(String dictionaryCode, Long dictionaryId) {
        return fySystemDictionaryService.dictionaryCodeCheck(dictionaryCode, dictionaryId);
    }

}
